package server

import (
	"context"
	"zk2/user_server/basic/config"
	__ "zk2/user_server/basic/proto"
	"zk2/user_server/model"
)

type Server struct {
	__.UnsafeUserServer
}

func (s *Server) ChatAdd(_ context.Context, in *__.ChatAddReq) (*__.ChatAddResp, error) {
	chat := model.Chat{
		UserId:    in.UserId,
		ReceiveId: in.ReceiveId,
		Message:   in.Message,
	}
	config.DB.Create(&chat)

	return &__.ChatAddResp{
		Id: chat.Id,
	}, nil
}
func (s *Server) FriendList(_ context.Context, in *__.FriendListReq) (*__.FriendListResp, error) {
	var friends []model.Friend
	config.DB.Find(&friends)
	var friendList []*__.FriendList
	for _, friend := range friends {
		list := __.FriendList{
			Name:   friend.Name,
			Photo:  friend.Photo,
			Age:    int64(friend.Age),
			Gender: friend.Gender,
		}
		friendList = append(friendList, &list)
	}

	return &__.FriendListResp{
		List: friendList,
	}, nil
}

func (s *Server) Greet(_ context.Context, in *__.StreamReq) (*__.StreamResp, error) {

	return &__.StreamResp{}, nil
}
